package pb

import (
	v1 "code.byted.org/bytertc/whiteboard_server/biz/api/pb/v1"
	"google.golang.org/protobuf/proto"
)

func NewEmptyCommand(command v1.Command) (msg proto.Message) {
	switch command {
	case v1.Command_kGetBoardInfo:
		msg = &v1.GetBoardInfoRequest{}
	case v1.Command_kEditing:
		msg = &v1.EditingRequest{}
	case v1.Command_kHeartBeat:
		msg = &v1.HeartBeatRequest{}
	case v1.Command_kGetActionCount:
		msg = &v1.GetActionCountRequest{}
	case v1.Command_kGetShapeSnapshot:
		msg = &v1.GetShapeSnapshotRequest{}
	case v1.Command_kCreateBoard:
		msg = &v1.CreateBoardRequest{}
	}
	return msg
}

func UnmarshalCommand(command v1.Command, data []byte) (msg proto.Message, err error) {
	msg = NewEmptyCommand(command)
	if msg != nil {
		err = proto.Unmarshal(data, msg)
	}
	return
}

func NewEmptyAction(actionType v1.ActionType) (msg proto.Message) {
	switch actionType {
	case v1.ActionType_kPen:
		msg = &v1.Pen{}
	case v1.ActionType_kLine:
		msg = &v1.Line{}
	case v1.ActionType_kArrow:
		msg = &v1.Arrow{}
	case v1.ActionType_kRect:
		msg = &v1.Rect{}
	case v1.ActionType_kCircle:
		msg = &v1.Circle{}
	case v1.ActionType_kText:
		msg = &v1.Text{}
	case v1.ActionType_kImage:
		msg = &v1.Image{}
	case v1.ActionType_kAudio:
		msg = &v1.Audio{}
	case v1.ActionType_kVideo:
		msg = &v1.Video{}
	case v1.ActionType_kErase:
		msg = &v1.Erase{}
	case v1.ActionType_kClearBoard:
		msg = &v1.ClearBoard{}
	case v1.ActionType_kCreatePage:
		msg = &v1.CreatePage{}
	case v1.ActionType_kFlipPage:
		msg = &v1.FlipPage{}
	case v1.ActionType_kDeletePage:
		msg = &v1.DeletePage{}
	case v1.ActionType_kChangePageBackground:
		msg = &v1.ChangePageBackground{}
	case v1.ActionType_kChangeBoardBackground:
		msg = &v1.ChangeBoardBackground{}
	case v1.ActionType_kSetActiveBoard:
		msg = &v1.SetActiveBoard{}
	case v1.ActionType_kCloseBoard:
		msg = &v1.CloseBoard{}
	case v1.ActionType_kZoomBoard:
		msg = &v1.ZoomBoard{}
	case v1.ActionType_kStepChange:
		msg = &v1.PptStepChange{}
	case v1.ActionType_kPptMediaChange:
		msg = &v1.PptMediaChange{}
	case v1.ActionType_kPptTriggerChange:
		msg = &v1.PptTriggerChange{}
	}
	return
}

func UnmarshalAction(actionType v1.ActionType, data []byte) (msg proto.Message, err error) {
	msg = NewEmptyAction(actionType)
	if msg != nil {
		err = proto.Unmarshal(data, msg)
	}
	return
}
